using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using UmlDesigner.Model;

namespace UmlDesigner
{
    internal partial class ClassProperties : Form
    {
        ClassWidget classWidget = null;
        ClassWidget targetClassWidget = null;

        internal ClassProperties(ClassWidget c)
        {
            InitializeComponent();
            Icon = Properties.Resources.ApplicationIcon;

            classWidget = new ClassWidget();
            targetClassWidget = c;

            targetClassWidget.ShallowCopyClassWidget(classWidget);

            nameTextBox.Text = c.name;

            GenerateCodePreview();
        }

        private void OnOkClicked(object sender, EventArgs e)
        {
            classWidget.ShallowCopyClassWidget(targetClassWidget);
        }

        private void nameTextBox_TextChanged(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Trim().Length > 0)
            {
                classWidget.name = nameTextBox.Text;
                GenerateCodePreview();
            }
        }

        private void GenerateCodePreview()
        {
            StringWriter exampleCode = new StringWriter();
            CodeGenerationSettings settings = new CodeGenerationSettings("", "GeneratedCode", CodeGenerationSettings.GenerationSource.SelectionOnly, false, false, false);
            settings.StartNewItem(exampleCode, 0);
            classWidget.GenerateCodeStub(settings);
            richTextBox1.Text = exampleCode.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            NewMethodAttributeForm dlg = new NewMethodAttributeForm(classWidget);
            dlg.ShowDialog();

            GenerateCodePreview();
        }
    }
}